package com.jiai.cloud.web;
import com.jiai.cloud.feign.GoodTypeAPI;
import com.jiai.cloud.feign.GoodsAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;



/**
 * Created by Administrator on 2017/5/31.
 */
@Controller
@RequestMapping(value="/goods")
public class GoodsController {
    @Autowired
    GoodsAPI goodsAPI;
    GoodTypeAPI goodTypeAPI;

    @RequestMapping(value = "addgoods", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ModelAndView addGoods() {
        ModelAndView view = new ModelAndView("goods/addgoods");
        try {
            view.addObject("goods", goodsAPI.addGoods(null));
            view.addObject("goodType", goodTypeAPI.addGoodType(null));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return view;
    }

    @RequestMapping(value = "/goodslist", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ModelAndView Goodslist(@RequestParam(defaultValue = "1") Integer page) {

        ModelAndView view = new ModelAndView("goods/goodslist");
        try {
            view.addObject("goods", goodsAPI.selectPage(page));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return view;
    }





}
